package com.spirng.leetcode.day09;

public class Test135 {
    public static void main(String[] args) {
        Test135 test135 = new Test135();
        test135.candy(new int[]{1,2,0});
    }
    public int candy(int[] ratings) {
        int[] candy=new int[ratings.length];
        for (int i = 0; i < candy.length; i++) {
            candy[i]=1;
        }
        for (int i = 1; i < ratings.length; i++) {
              if(ratings[i]-ratings[i-1]>0){
                  candy[i]=candy[i-1]+1;
              }
        }
        for (int i = ratings.length-2; i >0; i--) {
             if(ratings[i]>ratings[i+1]){
                 candy[i]=Math.max(candy[i],candy[i+1]+1);
             }
        }
        int res=0;
        for (int i = 0; i < candy.length; i++) {
            res+=candy[i];
        }
        return res;
    }
}
